package site.brucewu.aha.config.security;

//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpMethod;
//import org.springframework.security.config.Customizer;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.web.SecurityFilterChain;
//import org.springframework.web.cors.CorsConfiguration;
//import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
//
//import java.util.Arrays;
//
//@Configuration
//@EnableWebSecurity
//public class WebSecurityConfig {
//
//    @Bean
//    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
//        http
//                .csrf((csrf) -> csrf.disable())
//                .httpBasic(Customizer.withDefaults())
//                .formLogin(Customizer.withDefaults())
//                .cors((cors) -> cors
//                        .configurationSource(apiConfigurationSource()))
//                .authorizeHttpRequests(authorize -> authorize
//                        .requestMatchers("/actuator/**").permitAll()
//                        .requestMatchers("/instances").permitAll()
//                        .anyRequest().authenticated()
//                );
//
//        return http.build();
//    }
//
//
//    UrlBasedCorsConfigurationSource apiConfigurationSource() {
//        CorsConfiguration configuration = new CorsConfiguration();
//        configuration.setAllowedOrigins(Arrays.asList("http://localhost:5173"));
//        configuration.setAllowedMethods(Arrays.asList(
//                HttpMethod.GET.name()
//                ,HttpMethod.PATCH.name()
//                ,HttpMethod.HEAD.name()
//                ,HttpMethod.PUT.name()
//                ,HttpMethod.TRACE.name()
//                ,HttpMethod.POST.name()
//                ,HttpMethod.DELETE.name()
//                ,HttpMethod.OPTIONS.name()));
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        source.registerCorsConfiguration("/**", configuration);
//        return source;
//    }
//}
